package model

import (
	"car-rental-08-14/global"
	"gorm.io/gorm"
	"time"
)

type User struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:用户ID;primaryKey;not null;" form:"id" json:"id"`                                          // 用户ID
	Mobile    string         `gorm:"column:mobile;type:char(11);comment:手机号;not null;" form:"mobile" json:"mobile"`                                              // 手机号
	Password  string         `gorm:"column:password;type:char(32);comment:密码;not null;" form:"password" json:"password"`                                         // 密码
	Status    int8           `gorm:"column:status;type:tinyint(1);comment:状态 1:正常 2:冻结;not null;" form:"status" json:"status"`                                   // 状态 1:正常 2:冻结
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);comment:注册时间;not null;default:CURRENT_TIMESTAMP(3);" form:"created_at" json:"created_at"` // 注册时间
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);comment:修改时间;not null;" form:"updated_at" json:"updated_at"`                              // 修改时间
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" form:"deleted_at" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}

func (u *User) RegisterUser() error {
	return global.DB.Create(&u).Error
}
